<template>
  <div>
    <!-- input输入弹窗 -->
    <input-dialog
      v-if="inputDialogParams.visible"
      :params="inputDialogParams"
    />
  </div>
</template>

<script>
export default {
  components: {
    InputDialog: () => import('@/components/Dialog/InputDialog.vue')
  },
  data: () => {
    return {
      inputDialogParams: {
        visible: false
      }
    }
  },
  created() {
    this.$root.AomMainDialog = this
  },
  methods: {
    // 全局可以直接使用InputDialog弹窗
    showInputDialog(title, label, value, options) {
      options ??= {}
      return new Promise((resolve, reject) => {
        const dialog = this.inputDialogParams
        dialog.title = title
        dialog.label = label
        dialog.value = value || ''
        dialog.name = 'value'
        dialog.confirm = (res) => {
          dialog.visible = false
          resolve(res)
        }
        if (options.useCancel) {
          dialog.cancel = () => {
            dialog.visible = false
            reject()
          }
        }
        dialog.visible = true
      })
    }
  }
}
</script>

<style>
</style>
